package com.snts.synchronization.server.web;

import java.io.InputStream;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.catalina.core.ApplicationContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.PropertyConfigurator;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SyncServletContextListener implements ServletContextListener {

	private static final Log log = LogFactory.getLog(SyncServletContextListener.class);
	
	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void contextInitialized(ServletContextEvent event) {
		log.debug("contextInitialized");
		InputStream is = getClass().getClassLoader().getResourceAsStream("log4j.properties");
		PropertyConfigurator.configure(is);
		AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:com/snts/synchronization/applicationContext.xml");
		event.getServletContext().setAttribute(SyncServlet.SPRING_APPLICATION_CONTEXT_ATTR, applicationContext);
	}

}
